package com.example.androidproject.app.deprecated.temporarily_deprecated_adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.androidproject.R;

import com.example.androidproject.app.adapter.ClassifyOptionsAdapter;
import com.example.androidproject.myview.MyGridView;
import com.example.androidproject.utils.ResultsConstant;

/**
 * 苦思冥想 发现新大陆 此adapter 完全弃用 version 1.2.0
 */

public class ClassifyAdapter2 extends RecyclerView.Adapter {
    private final String TAG = "GGSTUDY";
    public final int Navigation = 0;
    public final int Content = 1;
    private final LayoutInflater layoutInflater;
    private final int classifyType;
    public int currentType = Navigation;

    private final Context mContext;

    public ClassifyAdapter2(Context mContext, int classifyType) {
        this.mContext = mContext;
        this.classifyType = classifyType;
        layoutInflater = LayoutInflater.from(mContext);
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        // 之所以会出现 两个全部 因为这里 拿了两次这个布局 所以把布局中的 两个gridview分开来就好了
        if (viewType == Navigation) {
            return new OptionViewHolder(mContext, layoutInflater.inflate(R.layout.classify_options_laytout, null));
        }
        if (viewType == Content) {
            return new ContentViewHolder(mContext, layoutInflater.inflate(R.layout.classify_content_layout, null));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (getItemViewType(position) == Navigation) {
            OptionViewHolder optionViewHolder = (OptionViewHolder) holder;
            optionViewHolder.setData();
        }
        if (getItemViewType(position) == Content) {
            ContentViewHolder contentViewHolder = (ContentViewHolder) holder;
            contentViewHolder.setData();
        }
    }

    class OptionViewHolder extends RecyclerView.ViewHolder {
        private final Context mContext;
        //        private final MyGridView gv_classify_nav;
        private final TextView btn_classify_options_all1;

        public OptionViewHolder(Context mContext, @NonNull View itemView) {
            super(itemView);
            this.mContext = mContext;
            this.btn_classify_options_all1 = itemView.findViewById(R.id.btn_classify_options_all1);
//            this.gv_classify_nav = itemView.findViewById(R.id.gv_classify_nav1);
        }

        public void setData() {
            ClassifyOptionsAdapter classifyOptionsAdapter = new ClassifyOptionsAdapter(mContext, ResultsConstant.OptionData, classifyType, btn_classify_options_all1);
//            gv_classify_nav.setAdapter(classifyOptionsAdapter);
        }
    }

    class ContentViewHolder extends RecyclerView.ViewHolder {
        private final Context mContext;
        private final MyGridView grid_classify_content;
        private final ClassifyContentAdapter2 classifyContentAdapter2;

        public ContentViewHolder(Context mContext, @NonNull View itemView) {
            super(itemView);
            this.mContext = mContext;
            this.grid_classify_content = itemView.findViewById(R.id.grid_classify_content);
            classifyContentAdapter2 = new ClassifyContentAdapter2(mContext, classifyType);
        }

        public void setData() {
            if (classifyType == 1) {
                grid_classify_content.setAdapter(classifyContentAdapter2);
            }
            if (classifyType == 2) {
                grid_classify_content.setAdapter(classifyContentAdapter2);
            }
        }
    }

    @Override
    public int getItemViewType(int position) {
        switch (position) {
            case Navigation:
                currentType = Navigation;
                break;
            case Content:
                currentType = Content;
                break;
        }
        return currentType;
    }

    @Override
    public int getItemCount() {
        return 2;
    }

}
